package net.ewon.avatar.common.pkg;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "avatarPackage")
@XmlRootElement(name = "AvatarPackage")
public class AvatarPackage {

	@Id
	private String id;
	private String name;
	private Version version;
	private String createdBy;
	private Date createdDate;
	private List<String> fileIds = new ArrayList<String>();

	public AvatarPackage() {
	}

	public AvatarPackage(String name, Version version, List<String> fileIds) {
		this(name, version, fileIds, "system", new Date());
	}

	public AvatarPackage(String name, Version version, List<String> fileIds,
			String createdBy, Date createdDate) {
		this.name = name;
		this.version = version;
		this.fileIds = fileIds;
		this.createdBy = createdBy;
		this.createdDate = createdDate;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Version getVersion() {
		return version;
	}

	public void setVersion(Version version) {
		this.version = version;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public synchronized List<String> getFileIds() {
		// When this class is used for restful service. fileIds don't get to be
		// initialized as we think
		if (this.fileIds == null) {
			this.fileIds = new ArrayList<String>();
		}
		return fileIds;
	}
	
	public void setFileIds(List<String> fileIds) {
		this.fileIds = fileIds;
	}

	public void addFileId(String fileId) {
		this.getFileIds().add(fileId);
	}

}
